package com.woniu.userservice.controller;

import com.woniu.userservice.entity.Collections;
import com.woniu.userservice.service.CollectionsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 收藏controller 包含 取消收藏 展示收藏功能
 * 2020/3/24 15:58
 * 张腾飞
 * @author dell
 */
@RestController
@RequestMapping("collections")
public class CollectionsController {
    @Resource
    private CollectionsService collectionsService;

    @GetMapping("selectOne")
    public Collections selectOne(Integer id) {
        return collectionsService.queryById(id);
    }

    /**
     *
     * @param id 商品id
     * @param userid 用户id
     * @return 取消收藏
     */
    @PostMapping("/deleteById")
    public String deleteById(@RequestParam(value = "id",required = true) Integer id ,@RequestParam(value = "userid",required = true) Integer userid){

        boolean bo  = collectionsService.deleteByShopId(id,userid);
        if (bo){
            return "取消成功";
        }else {
            return "取消失败";
        }
    }

    /**
     *
     * @param userId    用户id
     * @param goodsName  商品名字
     * @param collectionTime  时间
     * @return 模糊查询收藏
     */
    @PostMapping("/findShop")
    @ResponseBody
    public List<Collections> findShop(Integer userId , String goodsName, Date collectionTime, Double price){

        List<Collections> co = collectionsService.findByShop(userId,goodsName,collectionTime,price);
        if (co.size() != 0){
            return co;
        }else {
            return null ;
        }
    }

}